package com.ebj.demo.thrift.server;

import com.ebj.demo.thrift.constant.GlobalConstants;
import com.ebj.demo.thrift.generate.HelloMartinService;
import com.ebj.demo.thrift.impl.HelloMartinImpl;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;

/**
 * Created by xiangyongzhou on 2017/7/5.
 */
public class MyServer
{


    public static void main(String[] args)
    {
        MyServer myServer = new MyServer();
        myServer.starServer();


    }

    public void starServer()
    {
        System.out.println("HelloMartinService server starting...");
        HelloMartinService.Processor<HelloMartinService.Iface> tprocessor = new HelloMartinService.Processor<>(new HelloMartinImpl());
        try {
            TServerSocket serverTransport = new TServerSocket(GlobalConstants.SERVER_PORT);
            TServer.Args tArgs = new TServer.Args(serverTransport);
            tArgs.processor(tprocessor);
            tArgs.protocolFactory(new TCompactProtocol.Factory());
            TServer tServer = new TSimpleServer(tArgs);
            tServer.serve();
        }
        catch (TTransportException e) {
            e.printStackTrace();
        }
    }
}
